import 'package:get/get.dart';
import 'package:xvideos/hj_utils/api_service/mine_service.dart';
import 'package:xvideos/hj_utils/global.dart';

import '../../../hj_model/mine/excharge/recharge_list_model.dart';
import '../../../hj_model/mine/excharge/recharge_type_list_model.dart';
import 'online_pay_page.dart';

class MineChargeCoinLogic extends GetxController {
  int selectIndex = 0;
  bool isInitLoading = true;
  RechargeTypeModel? currentDiamondM;
  RechargeListModel? model;
  int payIndex = 0; //支付选择
  bool isPayLoading = false;

  @override
  onReady() async {
    super.onReady();
    loadData();
  }

  loadData() async {
    final res = await MineService.getNakeChatRechargeTypeList(1);
    isInitLoading = false;
    model = res;
    if (res != null) {
      res.list ??= [];
      if (res.list!.isNotEmpty) {
        currentDiamondM = res.list!.first;
      }
    }
    update();
  }

  //vip选择
  onChangItemSelect(int index) {
    selectIndex = index;
    payIndex = 0; //刷新支付选择
    currentDiamondM = model?.list?[index];
    update();
  }

  //切换支付方式
  onChangedPayType(int index) {
    payIndex = index;
    currentDiamondM = model?.list?[index];
    update();
  }

  //金币明细
  onJumpToBillList() {}

  //去支付,购买影视会员卡
  onGotoPay() async {
    print('onGotoPay = 购买会员", "支付购买会员');
    if (currentDiamondM == null) {
      showToast("请选择产品");
      return;
    }
    if (currentDiamondM!.rechargeTypeListUI.isEmpty) {
      showToast("未配置支付方式，请联系客服");
      return;
    }
    Get.bottomSheet(
        OnlinePayPage(
          coinRcModel: currentDiamondM,
        ),
        isScrollControlled: true);
  }
}
